
#include "udpcksum.h"
#include <stdio.h>
#include <stdlib.h>
#include <netinet/udp.h>
#include <setjmp.h>
#include <netdb.h>
#include <signal.h>
// #include <setjmp.h>
#include "sys/select.h"
#include <sys/signal.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <net/if.h>
#include <setjmp.h>

static jmp_buf jmpbuf;
static int     canjump;

void sig_alarm(int no) {

    if (canjump == 0) {

        return;
    }
    siglongjmp(jmpbuf, 1);
}

void test_udp() {

    volatile int nsent = 0, timeout = 3;
    struct udpiphdr * ui;

    signal(SIGALRM, sig_alarm);

    if (sigsetjmp(jmpbuf, 1)) {
        if (nsent >= 3) {
            printf("no response\n");
            exit(7);
        }
        printf("timeout\n");
        timeout *= 2;
    }
    canjump = 1;
    send_dns_query();
    nsent++;
    alarm(timeout);
    ui = udp_read();
    canjump = 0;
    // 提前触发
    alarm(0);
    if (ui->ui_sum == 0) {

        printf("UDP checksums off\n");
    }
    else {

        printf("UDP checksums on\n");
    }
}